const MAP_PLATFORMS = {
    amap: {
        name: '高德地图',
        geocodeUrl: 'https://restapi.amap.com/v3/geocode/geo',
        defaultKey: '62ce26652cf472468c38a10ff74d63c3',
        rateLimit: 100, // 毫秒
        timeout: 5000,
        buildParams: (address, key) => ({
            key: key,
            address: address,
            output: 'json'
        }),
        parseResponse: (data) => {
            if (data.status === '1' && data.geocodes && data.geocodes.length > 0) {
                const location = data.geocodes[0].location.split(',');
                return {
                    success: true,
                    coordinates: [parseFloat(location[0]), parseFloat(location[1])]
                };
            } else {
                return {
                    success: false,
                    error: data.info || '地理编码失败'
                };
            }
        }
    },
    
    tencent: {
        name: '腾讯位置服务',
        geocodeUrl: 'https://apis.map.qq.com/ws/geocoder/v1/',
        defaultKey: 'SXFBZ-GYWKJ-QEJFR-D3QQJ-6NWV5-LDFSN',
        rateLimit: 150, // 毫秒
        timeout: 6000,
        buildParams: (address, key) => ({
            key: key,
            address: address,
            output: 'json'
        }),
        parseResponse: (data) => {
            if (data.status === 0 && data.result && data.result.location) {
                const location = data.result.location;
                return {
                    success: true,
                    coordinates: [location.lng, location.lat]
                };
            } else {
                return {
                    success: false,
                    error: data.message || '地理编码失败'
                };
            }
        }
    },
    
    tianditu: {
        name: '天地图',
        geocodeUrl: 'http://api.tianditu.gov.cn/geocoder',
        defaultKey: '89f04c94b06f1783e5094c63a2fa02dc',
        rateLimit: 200, // 毫秒
        timeout: 8000,
        buildParams: (address, key) => ({
            tk: key,
            ds: JSON.stringify({
                keyWord: address
            })
        }),
        parseResponse: (data) => {
            if (data.status === '0' && data.location) {
                return {
                    success: true,
                    coordinates: [data.location.lon, data.location.lat]
                };
            } else {
                return {
                    success: false,
                    error: data.msg || '地理编码失败'
                };
            }
        }
    }
};

module.exports = { MAP_PLATFORMS };